package com.snails.tool.storage;

import android.content.Context;
import android.content.SharedPreferences;

import java.util.Set;

/**
 * @author lawrence
 */
public final class SharedPrefUtils {

    private SharedPreferences.Editor mEditor = null;
    private SharedPreferences mSharedPreferences = null;

    public SharedPrefUtils(Context ctx, String name) {
        mSharedPreferences = ctx.getSharedPreferences(name, Context.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
    }

    public void putString(String name, String value) {
        mEditor.putString(name, value);
    }

    public void removeCache(String name) {
        mEditor.remove(name);
        mEditor.commit();
    }

    public void putInt(String name, int value) {
        mEditor.putInt(name, value);
    }

    public void putFloat(String name, float value) {
        mEditor.putFloat(name, value);
    }

    public void putLong(String name, long value) {
        mEditor.putLong(name, value);
    }

    public void putBoolean(String name, boolean value) {
        mEditor.putBoolean(name, value);
    }

    public int getInt(String name, int defaultValue) {
        return mSharedPreferences.getInt(name, defaultValue);
    }

    public void putStringSet(String name, Set<String> value) {
        mEditor.putStringSet(name, value);
    }

    public boolean getBoolean(String name, boolean defaultValue) {
        return mSharedPreferences.getBoolean(name, defaultValue);
    }

    public float getFloat(String name, float defaultValue) {
        return mSharedPreferences.getFloat(name, defaultValue);
    }

    public long getLong(String name, long defaultValue) {
        return mSharedPreferences.getLong(name, defaultValue);
    }

    public String getString(String name, String defaultValue) {
        return mSharedPreferences.getString(name, defaultValue);
    }

    public void clear() {
        mEditor.clear();
        mEditor.commit();
    }

    public Set<String> getStringSet(String name, Set<String> defaultValue) {
        return mSharedPreferences.getStringSet(name, defaultValue);
    }

    public void commit() {
        mEditor.commit();
    }

}

